package com.duanjw.bank.rate.core;

import cn.hutool.json.JSONObject;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.web.client.RestTemplate;

/**
 * 银行信息同步到 niceflow
 *
 * @author duanjw
 * @date 2024/4/7
 */
public class BankInfoSyncNiceFlow {

    public void sendToNiceFlow(String bankName, BankRate bankRate) {
        RestTemplate restTemplate = new RestTemplate();

        HttpHeaders headers = new HttpHeaders();
        headers.add("Content-Type", "application/json");
        headers.add("appId", "6612aa14b3fec81b4047ce11");
        headers.add("Authorization", "Bearer tXnmellIPITPgistz-1zFQKEQ4M9iMYxLx7Tkyfb-A0fewlADFQLmSmJ4vu-byGsfdouBocV9DA4thsa9FX7aoK1JEpxTeowwG_fICki8lJvHwybtR6gcPG2C69SJ527");
        JSONObject entries = new JSONObject(bankRate);
        entries.put("yinxingmingcheng", bankName);
        entries.setDateFormat("yyyy-MM-dd");
        HttpEntity<?> requestEntity = new HttpEntity<>(entries.toString(), headers);
        ResponseEntity<String> exchanged = restTemplate.exchange("https://niceflow.duanjw.com/api/workflow/open-api/forms/yinxinglilv/data", HttpMethod.POST, requestEntity, String.class);
        System.out.println(exchanged);
    }
}
